#include "stdafx.h"

#include <MyFC/Event.h>
#include <algorithm>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

namespace My {

void EventDispatcher::DispatchEvent(Event & e)
{
	std::list<EventListener *>::iterator it, tmp;
	for (it = m_Listeners.begin(); it != m_Listeners.end(); ) {
		(tmp = it)++;
		(* it)->ProcessEvent(e); // it may no longer be valid!
		it = tmp;
	}
}

void EventDispatcher::Attach(EventListener * ptr)
{
	m_Listeners.push_back(ptr);
}

void EventDispatcher::Detach(EventListener * ptr)
{
	m_Listeners.remove(ptr);
}

} // My

